<template>
  <div class="loading-container">
    <div
      class="loading-spinner"
      :style="{
        width: size,
        height: size,
        borderWidth: borderWidth,
        background: gradientBackground
      }"
    ></div>
    <p class="loading-text" v-if="text">{{ text }}</p>
  </div>
</template>

<script>
export default {
  name: 'LoadingSpinner',
  props: {
    // 大小，如 "40px"
    size: {
      type: String,
      default: '40px'
    },
    // 边框宽度
    borderWidth: {
      type: String,
      default: '3px'
    },
    // 显示文本
    text: {
      type: String,
      default: ''
    },
    // 渐变色数组（默认黑到白）
    colors: {
      type: Array,
      default: () => ['#000000', '#ffffff']
    }
  },
  computed: {
    gradientBackground() {
      return `conic-gradient(${this.colors.join(', ')})`
    }
  }
}
</script>

<style scoped>
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.loading-spinner {
  border-radius: 50%;
  animation: spin 1s linear infinite;
  box-sizing: border-box;
  mask: radial-gradient(farthest-side, transparent calc(100% - var(--bw)), black 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--bw)), black 0);
  /* --bw 用于动态控制边框宽度 */
  --bw: 3px;
}

.loading-text {
  margin-top: 8px;
  font-size: 12px;
  color: #718096;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
</style>
